package com.taysear.parcel.fieldfactory;

import com.taysear.parcel.util.Constants;
import com.vaadin.addon.jpacontainer.fieldfactory.FieldFactory;
import com.vaadin.data.Item;
import com.vaadin.ui.Component;
import com.vaadin.ui.Field;
import com.vaadin.ui.TextField;

@SuppressWarnings("serial")
public class StationStatusFieldFactory extends FieldFactory {
	
	public final TextField stationStatusId = new TextField("Id");
	final TextField description = new TextField("Description");

	@Override
	public Field createField(Item item, Object propertyId, Component uiContext) {
		Field f;
		if ("stationStatusId".equals(propertyId)) {
			stationStatusId.setRequired(true);
			stationStatusId.setWidth(Constants.COMMON_FIELD_WIDTH);
			return stationStatusId;
		} else if ("description".equals(propertyId)) {
			description.setRequired(true);
			description.setWidth(Constants.COMMON_FIELD_WIDTH);
			description.setRequiredError("Description is required");
			description.setNullRepresentation("");
			return description;
		} else {
			// Use the super class to create a suitable field base on the
			// property type.
			f = super.createField(item, propertyId, uiContext);
		}
		return f;
	}
}
